home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4455 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.1 KB

  1. Path: colossus.holonet.net!russell
  2. From: russell@news.mdli.com (Russell Blackadar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: why is dat ?
  5. Date: 30 Jan 1996 08:59:36 GMT
  6. Organization: HoloNet National Internet Access System: 510-704-1058/modem
  7. Message-ID: <4ekmlo$k7f@colossus.holonet.net>
  8. References: <310DCC58.798E@pergamon.isar.de>
  9. NNTP-Posting-Host: jubal.mdli.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Gerson Kurz (dekonstruktor@pergamon.isar.de) wrote:
  13. : hi guys, this is my first msg here so I don't know if this has 
  14. : been answered 10^50 times before but here it goes:
  15.  
  16. : class A {};
  17. : class B : public A {};
  18.  
  19. : B* pointer_to_B;
  20. : A** pointer_to_pointer_to_A = &pointer_to_B;
  21.  
  22. This is an unsafe conversion.  Suppose you wrote the above, 
  23. and then wrote the following two statememts:
  24.  
  25.  *pointer_to_pointer_to_A = new A; // looks reasonable, eh?  but we
  26.                                    // change pointer_to_B, so now it
  27.  pointer_to_B->some_B_member();    // CRASH!  points to an A, not a B
  28.  
  29. Therefore, the automatic conversion must not be allowed.  You can go
  30. from B* to A*, but not B** to A**.
  31. --
  32. Russell Blackadar,   russell@mdli.com
  33.